using System;
using System.Globalization;
using System.Web.UI;
using Sedna.Domain;
using Nullables;

namespace Sedna.Core.Controller.Configurations
{
	public class CurrencyDataTranslator : BaseDataTranslator, IDataTranslator
	{
        private string format = "{1} {0}";
        private bool absValue = true;

	    public bool AbsValue
	    {
	        get { return absValue; }
	        set { absValue = value; }
	    }

	    public string Format
        {
            get { return format; }
            set { format = value; }
        }
	    
		public override object UnsafeTranslate(Control control, object value, Type targetType)
		{
            MonetaryAmount amount = value as MonetaryAmount;
            if (amount==null)
            {
                amount = MonetaryAmount.Default;
            }
            return String.Format(format, absValue ? Math.Abs(amount.FullAmount) : amount.FullAmount, amount.Currency);
		}
	}
}
